package com.service;

import com.mapper.ClubMemberMapper;
import com.service.impl.ClubMemberServiceImpl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;

/**
 * <p>
 * 社团成员信息管理 Service 测试类
 * </p>
 * @author 34448
 */
public class ClubMemberServiceTest {

    @Mock
    private ClubMemberMapper clubMemberMapper;

    @InjectMocks
    private ClubMemberServiceImpl clubMemberService;

    @BeforeEach
    public void setUp() {
        MockitoAnnotations.openMocks(this);
    }

    @Test
    public void testCountClubMembersByYear() {
        Integer year = 2023;
        List<Map<String, Object>> expected = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        map.put("year", year);
        map.put("count", 10);
        expected.add(map);

        when(clubMemberMapper.countClubMembersByYear(year)).thenReturn(expected);

        List<Map<String, Object>> result = clubMemberService.countClubMembersByYear(year);
        assertEquals(expected, result);
    }

    @Test
    public void testCountClubMembersAllYears() {
        List<Map<String, Object>> expected = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        map.put("year", 2023);
        map.put("count", 10);
        expected.add(map);

        when(clubMemberMapper.countClubMembersAllYears()).thenReturn(expected);

        List<Map<String, Object>> result = clubMemberService.countClubMembersAllYears();
        assertEquals(expected, result);
    }

    @Test
    public void testCountClubMembersByYearInvalidYear() {
        assertThrows(IllegalArgumentException.class, () -> clubMemberService.countClubMembersByYear(-1));
    }
}